<?php
/**
 * Created by PhpStorm.
 * User: jin
 * Date: 2015/8/26
 * Time: 14:53
 */

namespace Home\Model;
use Think\Model;

class DoctorModel extends Model
{
    static private $tName = 'hospital_doctor';
    /**
     * 添加单个医生
     * @param string $doctorName
     * @return int $doctorId
     */
    static public function addDoctor($doctorName)
    {
        return M()->table(self::$tName)->add(array('doc_name'=>$doctorName));
    }

    static public function addDoc()
    {

            $data = array(
                'doc_name'=>I('post.doc_name'),
                'doc_title'=>I('post.doc_title'),
                'doc_goodat'=>I('post.doc_goodat'),
                'doc_hos'=>I('post.doc_hos'),
                'doc_office'=>I('post.doc_office'),
                'doc_detail'=>I('post.doc_detail'),
                'doc_comment'=>I('post.doc_comment'),
            );
            //插入医院主表数据
        return M()->table(self::$tName)->add($data);
        //return M()->table(self::$tName)->add($data);
    }



    /**
     * 添加多个用户
     * @param array $doctorName
     * @return array $doctorId
     */
    static public function addDoctors($doctorName)
    {
        $doctorIdArr = array();
        foreach($doctorName as $doctorNameKey => $doctorNameValue)
        {
            $tempId = self::addDoctor($doctorNameValue);
            if($tempId) $doctorIdArr[] = $tempId;
        }
        return $doctorIdArr;
    }

    /**
     * 删除医生
     * @param $hosId
     * @return mixed
     */
    static public function delDoctorsForDocId($docId)
    {
        $where = array();
        //根据传入变量类型确认where条件
        if(is_array($docId))
        {
            $where = array('doc_id'=>array('in',$docId));
        }
        else if(is_numeric($docId))
        {
            $where = array('doc_id'=>$docId);
        }
        //删除医生
        if(count($where))
        {
            return M()->table(self::$tName)->where($where)->delete();
        }
        else
        {
            return false;
        }
    }
}